import { Banner } from "../../http/http";

const app = getApp();

Page({
  data: {
    startSwiper: [],
    swiperMaxNumber: 0,
    swiperCurrent: 0,
  },
  //事件处理函数
  onLoad: function (options) {
    let { startSwiper } = this.data;

    var start = wx.getStorageSync("start");
    if (start != null && start != "") {
      // 跳转到toolbar
      wx.switchTab({
        url: "/pages/index/index",
      });
    }
    Banner().then((res) => {
      console.log(res);
      if (res.msg == "success") {
        res.data.map((v) => {
          if (v.type == "app") {
            startSwiper.push(v);
          }
        });
      }
      this.setData({
        startSwiper,
        swiperMaxNumber: startSwiper.length,
      });
    });
  },
  button(e) {
    console.log(e);
    wx.switchTab({
      url: "/pages/index/index",
    });
  },
  swiperchange: function (e) {
    this.setData({
      swiperCurrent: e.detail.current,
    });
  },
  imgClick() {
    if (this.data.swiperCurrent + 1 != this.data.swiperMaxNumber) {
      wx.showToast({
        title: "左滑进入",
        icon: "none",
      });
    }
  },
});
